package jdklearn.collectionAndMap.conllection.set;

/**
 * author Veng Su
 * email  1344114844@qq.com
 * date   18-9-1 下午2:32
 */
import java.util.*;

class M
{
    int age;
    public M(int age)
    {
        this.age = age;
    }
    public String toString()
    {
        return "M[age:" + age + "]";
    }
}

public class TestTreeSetDefine
{
    public static void main(String[] args)
    {
        TreeSet<M> ts = new TreeSet<M>(new Comparator()
        {
            //根据M对象的age属性来决定大小
            public int compare(Object o1, Object o2)
            {
                M m1 = (M)o1;
                M m2 = (M)o2;
                return m1.age > m2.age ? -1
                        : m1.age < m2.age ? 1 : 0;
            }
        });
        ts.add(new M(5));
        ts.add(new M(-3));
        ts.add(new M(9));
        System.out.println(ts);
    }
}
